<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Vote
 * @copyright  Copyright 2011 KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 * @version    $Id: index.tpl 2011-03-09 01:11:30 idris $
 * @author     Idris
 */
?>

<h2>
  <?php echo $this->translate('KEENONWEB Core Module') ?>
</h2>

<?php if( count($this->navigation) ): ?>
<div class='tabs'>
  <?php
	// Render the menu
	//->setUlClass()
  echo $this->navigation()->menu()->setContainer($this->navigation)->render()
  ?>
</div>
<?php endif; ?>

<br />

<p>
  <?php echo $this->translate('KOWCORE_FEATURED_PAGE_DESCR'); ?>
</p>

<br />

<script type="text/javascript">
var url = "<?php echo $this->url(array('module' => 'kowcore', 'controller' => 'manage', 'action' => 'index', 'page' => $this->page), 'admin_default', array('reset' => true)); ?>";
en4.core.runonce.add(function(){
  $('type').addEvent('change', function(){
    var value = this.value;
    window.location.href = url + '/type/' + value;
  });
});

function selectAll()
{
  var i;
  var multimodify_form = $('multimodify_form');
  var inputs = multimodify_form.elements;
  for (i = 1; i < inputs.length - 1; i++) {
    if (!inputs[i].disabled) {
      inputs[i].checked = inputs[0].checked;
    }
  }
}
</script>

<div class="filter_form">
  <?php echo $this->form->render($this); ?>
</div>
<div class="clr"></div>

<br />

<div class='admin_results'>
  <div>
    <?php $memberCount = $this->paginator->getTotalItemCount() ?>
    <?php echo $this->translate(array("%s ".$this->type." found", "%s ".$this->type."s found", $memberCount), ($memberCount)) ?>
  </div>
  <div>
    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'pageAsQuery' => true
    )); ?>
  </div>
</div>

<br />

<?php if ($this->paginator->getTotalItemCount()): ?>

<div class="admin_table_form">
<form id='multimodify_form' method="post" action="<?php echo $this->url(array('module' => 'kowcore', 'controller' => 'manage', 'action' => 'multy-modify', 'type' => $this->type, 'page' => $this->page), 'admin_default', array('reset' => true)); ?>">
  <table class='admin_table kowcore_table'>
    <thead>
      <tr>
        <th style='width: 1%;'><input onclick="selectAll()" type='checkbox' class='checkbox'></th>
        <th style='width: 1%;'><?php echo $this->translate("ID") ?></th>
        <th><?php echo $this->translate("Title") ?></th>
        <?php if ($this->type != 'user'): ?><th><?php echo $this->translate("Descr") ?></th><?php endif; ?>
        <th width="1%"><?php echo $this->translate("Featured") ?></th>
        <th style='width: 1%;'><?php echo $this->translate("Creation/Signup Date") ?></th>
        <?php if ($this->type != 'user'): ?><th style='width: 1%;'><?php echo $this->translate("Owner") ?></th><?php endif; ?>
        <th style='width: 1%;' class='admin_table_options'><?php echo $this->translate("Options") ?></th>
      </tr>
    </thead>
    <tbody>
      <?php if( count($this->paginator) ): ?>
        <?php foreach( $this->paginator as $item ):
          $user = isset($item->user_id) ? $this->item('user', $item->user_id) : $this->item('user', $item->owner_id);
          $isFeatured = in_array($item->getIdentity(), $this->fids);
          ?>
          <tr>
            <td><input name='modify[]' value='<?php echo $item->getIdentity();?>' type='checkbox' class='checkbox' /></td>
            <td><?php echo $item->getIdentity(); ?></td>
            <td class='admin_table_bold'>
              <?php echo $this->htmlLink($item->getHref(), $this->string()->truncate($item->getTitle(), 25),array('target' => '_blank')); ?>
            </td>
            <?php if ($this->type != 'user'): ?>
            <td>
              <?php echo $this->string()->truncate($item->getDescription(), 100); ?>
            </td>
            <?php endif; ?>
            <td align="center">
              <?php echo $isFeatured ? $this->translate('Yes') :  $this->translate('No'); ?>
            </td>
            <td><?php echo $item->creation_date ?></td>
            <?php if ($this->type != 'user'): ?><td class='admin_table_user'><?php echo $this->htmlLink($user->getHref(), $user->getTitle(), array('target' => '_blank')) ?></td><?php endif; ?>
            <td class='admin_table_options' align="center">
              <?php if ( !$isFeatured ): ?>
                <?php echo $this->htmlLink( $this->url(array('module' => 'kowcore', 'controller' => 'manage', 'action' => 'set-featured', 'id' => $item->getIdentity()), 'admin_default'),
                  '&nbsp;' , array('class' => 'featured', 'title' => 'Set Featured') ); ?>
              <?php else: ?>
                <?php echo $this->htmlLink( $this->url(array('module' => 'kowcore', 'controller' => 'manage', 'action' => 'set-unfeatured', 'id' => $item->getIdentity()), 'admin_default'),
                  '&nbsp;' , array('class' => 'unfeatured', 'title' => 'Unset Featured') ); ?>
              <?php endif; ?>
            </td>
          </tr>
        <?php endforeach; ?>
      <?php endif; ?>
    </tbody>
  </table>
  <br />
  <div class='buttons'>
    <button type='submit' name="submit_button" value="set-featured"><?php echo $this->translate("Set Featured") ?></button>
    <button type='submit' name="submit_button" value="unset-featured"><?php echo $this->translate("Unset Featured") ?></button>
  </div>
</form>
</div>

<?php else: ?>

<div class="tip">
	<span>
		<?php echo $this->translate("There are no items created by your members yet."); ?>
	</span>
</div>

<?php endif; ?>